﻿#pragma once
#include <fstream>
#include <string>
#include <iostream>
#include <ctime>
#include <Windows.h>

namespace sy
{
namespace tools
{
class log
{
public:
	void Write(std::string str)
	{
		static SYSTEMTIME curTime;
		GetLocalTime(&curTime);
		logFile << "[" << curTime.wYear << "/" << curTime.wMonth << "/" << curTime.wDay << " " << curTime.wHour << ":" << curTime.wMinute << ":" << curTime.wSecond << "]" << str << std::endl;
	}

	static log* GetInstance()
	{
		if (instance == nullptr)
			instance = new log();
		return instance;
	}

private:
	static log * instance;
	
	std::fstream logFile;

	log() 
	{
		logFile.open("./log.txt",std::ios::app);
		if (!logFile.is_open())
		{
			std::cout << "日志文件打开失败！" << std::endl;
			return;
		}
	}
	~log() 
	{
		logFile.close();
	}
};

log& Log();

}
}

